﻿using System;
using System.Collections.Generic;
using System.Text;
using Barbar.MapReport.Common.Drawing;
using Barbar.MapReport.DataSource;
using Barbar.MapReport.Common;
using System.Collections.ObjectModel;

namespace Barbar.MapReport.HtmlRender.Operations.Regions {
  [Serializable]
  internal class RegionListWrapper<T> : IGeoBound where T : RegionList {
    private T m_RegionList;
    private GeoBound m_GeoBound;

    public RegionListWrapper(T regionList) {
      m_RegionList = regionList;
      Collection<Polygon> geometries = new Collection<Polygon>();
      foreach (string regionId in regionList.RegionIds) {
        ZoomLevel zoomLevel = DataSourceManager.ZoomLevels.GetZoomLevel(ZoomLevelCollection.MaxGoogleZoomLevel);
        Polygon polygon = DataSourceManager.GetRegionGeometry(regionId, zoomLevel);
        geometries.Add(polygon);
      }
      m_GeoBound = GeoBound.ComputeSharedGeoBound<Polygon>(geometries);
    }

    public T RegionList {
      get { return m_RegionList; }
    }

    #region IGeoBound Members

    public IGeoPoint Northeast {
      get { return m_GeoBound.Northeast; }
    }

    public IGeoPoint Southwest {
      get { return m_GeoBound.Southwest; }
    }

    #endregion
  }
}
